package com.baomidou.springboot.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.springboot.entity.Announcement;
import com.baomidou.springboot.mapper.AnnouncementMapper;
import com.baomidou.springboot.service.AnnouncementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 人才招聘 服务实现类
 * </p>
 *
 * @author QQQ
 * @since 2018-06-19
 */
@Service
public class AnnouncementServiceImpl implements AnnouncementService {

    @Autowired
    private AnnouncementMapper announcementMapper;

    @Override
    public void save(Announcement announcement) {
        announcement.setCreateDate(new Date());
        announcementMapper.insert(announcement);
    }

    @Override
    public void delete(String id) {
        announcementMapper.deleteById(id);
    }

    @Override
    public Announcement edit(String id) {
        return announcementMapper.selectById(id);
    }

    @Override
    public void update(Announcement announcement) {
        announcement.setModifyDate(new Date());
        announcementMapper.updateById(announcement);
    }

    @Override
    public Announcement view(String id) {
        return announcementMapper.selectById(id);
    }

    @Override
    public Page<Announcement> list(Page<Announcement> page, String search) {
        if (0 == page.getSize()) {
            page.setSize(10);
        }
        if (0 == page.getCurrent()) {
            page.setCurrent(1);
        }
        List<Announcement> announcementList = announcementMapper.findByDateDesc(page, search);
        page.setRecords(announcementList);
        return page;
    }

    @Override
    public void deleteBatch(List<String> ids) {
        if (null == ids) {
            return;
        }
        announcementMapper.deleteBatchIds(ids);
    }
}
